package com.jlee.android.pimclient.activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;

import com.jlee.android.pimclient.PIMClientConstant;
import com.jlee.android.pimclient.R;

public class PIMClientSMSSettingActivity extends Activity {
	CheckBox mDateCB;
	CheckBox mBodyCB;
	CheckBox mTypeCB;
	CheckBox mNumberCB;
	
	SharedPreferences mSettings;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.sms_setting);
		setTitle(R.string.title_sms_setting);

		mSettings = getSharedPreferences(PIMClientConstant.PREFS_NAME, MODE_PRIVATE);
		
		mDateCB = (CheckBox) findViewById(R.id.smsDate);
		mBodyCB = (CheckBox) findViewById(R.id.smsBody);
		mTypeCB = (CheckBox) findViewById(R.id.smsType);
		mNumberCB = (CheckBox) findViewById(R.id.smsNumber);

		final Button saveButton = (Button) findViewById(R.id.save);
		saveButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				doSave();
			}
			
		});
		
		initChecked();
	}

	private void initChecked() {
		mDateCB.setChecked(mSettings.getBoolean(
				PIMClientConstant.PREFS_KEY_SMS_DATE, true));
		mBodyCB.setChecked(mSettings.getBoolean(
				PIMClientConstant.PREFS_KEY_SMS_MESSAGE, true));
		mTypeCB.setChecked(mSettings.getBoolean(
				PIMClientConstant.PREFS_KEY_SMS_TYPE, true));
		mNumberCB.setChecked(mSettings.getBoolean(
				PIMClientConstant.PREFS_KEY_SMS_NUMBER, true));
	}
	
	void doSave() {
		Editor editor = mSettings.edit();

		editor.putBoolean(PIMClientConstant.PREFS_KEY_SMS_DATE, 
				mDateCB.isChecked());
		editor.putBoolean(PIMClientConstant.PREFS_KEY_SMS_MESSAGE, 
				mBodyCB.isChecked());
		editor.putBoolean(PIMClientConstant.PREFS_KEY_SMS_TYPE, 
				mTypeCB.isChecked());
		editor.putBoolean(PIMClientConstant.PREFS_KEY_SMS_NUMBER, 
				mNumberCB.isChecked());

		editor.commit();
		finish();
	}
}
